package com.zjw.zy.componse.demo.ext

import androidx.lifecycle.viewModelScope
import com.zjw.zy.componse.demo.base.BaseViewModel
import kotlinx.coroutines.*
import kotlin.coroutines.CoroutineContext
/**
 * @author     ：zhong.jw
 * @date       ：Created in 2023/2/16 15:01
 * @description：
 */


fun BaseViewModel.launchInDefault(
    context: CoroutineContext = Dispatchers.Default,
    start: CoroutineStart = CoroutineStart.DEFAULT,
    block: suspend CoroutineScope.() -> Unit
): Job {
    return this.viewModelScope.launch(context, start, block)
}

fun BaseViewModel.launchInMain(
    context: CoroutineContext = Dispatchers.Main,
    start: CoroutineStart = CoroutineStart.DEFAULT,
    block: suspend CoroutineScope.() -> Unit
): Job {
    return this.viewModelScope.launch(context, start, block)
}

fun BaseViewModel.launchInIo(
    context: CoroutineContext = Dispatchers.IO,
    start: CoroutineStart = CoroutineStart.DEFAULT,
    block: suspend CoroutineScope.() -> Unit
): Job {
    return this.viewModelScope.launch(context, start, block)
}